/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.unesp.rc.lcpjcontacts.utils;

import javax.swing.text.MaskFormatter;


/**
 * The Class FormatUtils.
 *
 * @author rafaelt
 */
public class FormatUtils {

    /**
     * Mask.
     *
     * @param s the s
     * @return the mask formatter
     */
    public static MaskFormatter mask(String s) {
        MaskFormatter formato = null;
        try {
            if (s.equals("cpf")) {
                formato = new MaskFormatter("###.###.###-##");
            } else if (s.equals("cep")) {
                formato = new MaskFormatter("#####-###");
            } else if (s.equals("uf")) {
                formato = new MaskFormatter("UU");
            } else if (s.equals("fone")) {
                formato = new MaskFormatter("(##) ####-####");
            } else if (s.equals("data")) {
                formato = new MaskFormatter("## / ## / ####");
            }

            formato.setPlaceholderCharacter('_');
            formato.setCommitsOnValidEdit(true);
            formato.setValueContainsLiteralCharacters(false);
        } catch (java.text.ParseException e) {
            System.out.println(e.getMessage());
        }
        return formato;
    }
}
